package org.springblade.flow.repair.parts.listener;

import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.flow.repair.parts.vo.ProcessTaskVO;
import org.springblade.modules.admin.service.MaintainPartsWorkService;
import org.springframework.stereotype.Component;

/**
 * @Description 更换配件-终止结束事件监听器
 * @Author ysq
 * @Date 2022/6/29
 **/
@Slf4j
//@Component
public class EndEvenListener implements ExecutionListener {

	private Expression status;

	@Override
	public void notify(DelegateExecution execution) {
		log.info(">>>>>>>>>流程终止事件监听器>>>>>>>>>");
		MaintainPartsWorkService businessService = SpringUtil.getBean(MaintainPartsWorkService.class);
		ProcessTaskVO processTaskVO = new ProcessTaskVO();
		processTaskVO.setProcessDefinitionId(execution.getProcessDefinitionId());
		processTaskVO.setProcessInstanceId(execution.getProcessInstanceId());
		processTaskVO.setEventName(execution.getEventName());
		processTaskVO.setStatus(String.valueOf(status.getValue(execution)));
		businessService.updatePartsWorkStatus(processTaskVO);
	}
}
